/* This Queue implementation of singly linked list in C implements 3 
 * operations: add, remove and print elements in the list.  Well, actually, 
 * it implements 4 operations, lats one is list_free() but free() should not 
 * be considered the operation but  a mandatory practice like brushing 
 * teeth every morning, otherwise you will end up loosing some part of 
 * your body(the software) Its is the modified version of my singly linked 
 * list suggested by Ben from comp.lang.c . I was using one struct to do 
 * all the operations but Ben added a 2nd struct to make things easier and 
 * efficient.
 *
 * I was always using the strategy of searching through the list to find the
 *  end and then addd the value there. That way list_add() was O(n). Now I 
 * am keeping track of tail and always use  tail to add to the linked list, so 
 * the addition is always O(1), only at the cost of one assignment.
 *
 *
 * VERISON 0.5
 *
 */

#include  <stdio.h>
#include  <stdlib.h>
#include  <string.h>
#include "uart.h"
 
 
struct my_struct
{
  int num;
  struct my_struct* next;
};
 
 
struct my_list
{
  struct my_struct* head;
  struct my_struct* tail;
};
 
 
struct my_list* list_add_element( struct my_list*, const int);
struct my_list* list_remove_element( struct my_list*);
 
 
struct my_list* list_new(void);
struct my_list* list_free( struct my_list* );
 
void list_print( const struct my_list* );
void list_print_element(const struct my_struct* );



/*
int main(void)
{
  struct my_list*  mt = NULL;
 
  mt = list_new();
  list_add_element(mt, 1);
  list_add_element(mt, 2);
  list_add_element(mt, 3);
  list_add_element(mt, 4); 
   
  list_print(mt);
 
  list_remove_element(mt);
  list_print(mt);
 
  list_free(mt);   // always remember to free() the malloc()ed memory
  free(mt);        //free() if list is kept separate from free()ing the structure, I think its a good design
  mt = NULL;      //after free() always set that pointer to NULL, C will run havon on you if you try to use a dangling pointer
 
  list_print(mt);
 
  return 0;
}

*/
